package com.c.ctgproject.adapter.doorkeeper

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.c.ctgproject.R
import com.c.ctgproject.entity.doorkeeper.DoorkeeperPartOutEntity
import com.c.ctgproject.utils.handlerNull

/**
 *作者:LiBW
 *创建日期: 2020/9/12
 *描述:配件出库list的子list适配器
 */
class DoorkeeperPartListChildAdapter(private val context: Context, private val partsList: List<DoorkeeperPartOutEntity.DataBean.ListBean.PartsInfosBean>) : RecyclerView.Adapter<DoorkeeperPartListChildAdapter.ViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_doorkeeper_part_list_child, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val data = partsList[position]
        holder.mPartNameTV.text = data.partsName.handlerNull()
        holder.mApplyCountTV.text = data.partsNumber.handlerNull()
        var weight = data.partsWeight.handlerNull()
        if (weight != "") {
            weight = "${weight}KG"
        }
        holder.mApplyWeightTV.text = weight
    }

    override fun getItemCount(): Int {
        return partsList.size
    }

    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val mPartNameTV: TextView = itemView.findViewById(R.id.mPartNameTV)
        val mApplyCountTV: TextView = itemView.findViewById(R.id.mApplyCountTV)
        val mApplyWeightTV: TextView = itemView.findViewById(R.id.mApplyWeightTV)
    }
}